var id=2;//员工id
var obj=JSON.parse(sessionStorage.getItem("customer"));
var id=obj.id;
//留言列表

function message() {

    $.ajax({
        url: "/meeting/checkMessageArrangement",
        type: "POST",
        data:{"id":id},
        dataType: "json",
        success:function (result) {
            var str="";
            var but="";
            if (result!=null) {
                for (var i = 0; i < result.length; i++) {
                    str += "<tr>\n" +
                        "\n" +
                        "            <td><input type=\"checkbox\" value='"+result[i].informationid+"' name='check'></td>\n" +
                        "            <td>" + result[i].title + "</td>\n" +
                        "            <td>" + result[i].onlinuemessage + "</td>\n" +
                        "            <td><a href=\"#\">删除</a><span style='display: none'>"+result[i].informationid+"</span></td>\n" +
                        "\n" +
                        "\n" +
                        "        </tr>";
                }
                but+="<li>\n" +
                    "            <label>&nbsp;</label>\n" +
                    "            <input name=\"\" type=\"button\" class=\"btn\" value=\"确认提交\" id=\"btn\" />&nbsp;\n" +
                    "            <input name=\"\" type=\"button\" class=\"btn\" value=\"返回\" onclick=\"window.history.back()\" />\n" +
                    "        </li>";
            }
            $(".tablelist:eq(0) tbody").html(str);
            $(".forminfo").html(but);
            commit();
            de();
        }

    });

}

//提交
function commit() {
    $("#btn").click(function () {
        var arr=[];//勾选到的列
        $("input[name='check']:checked").each(function () {
            arr.push($(this).val());
        })
        if (arr.length==0){
            alert("请先选择");
            return;
        }
        $(".tip").fadeIn(200);
        $(".sure").click(function(){
            $.ajax({
                url: "/meeting/updateMessageArrangement",
                type: "POST",
                data:{"arr":arr},
                dataType: "json",
                success:function (result) {

                    if (result==true){
                        alert("提交成功");
                    }else {
                        alert("提交失败")
                    }
                    message();
                }


            });
            $(".tip").fadeOut(100);
        });

        $(".cancel").click(function(){
            $(".tip").fadeOut(100);
        });

    })
}

//删除
function de() {
    $(".tablelist tbody tr td a").click(function () {

        let index = $(".tablelist tbody tr td a").index(this);
        var informationid=$(".tablelist tbody tr td a:eq("+index+")").next("span").html();
        $(".tip").fadeIn(200);
        $(".sure").click(function(){
            $.ajax({
                url: "/meeting/deleteMessageArrangement",
                type: "POST",
                data:{"informationid":informationid},
                dataType: "json",
                success:function (result) {

                    if (result==true){
                        alert("删除成功");
                    }else {
                        alert("删除失败")
                    }
                    message();
                }


            });
            $(".tip").fadeOut(100);
        });

        $(".cancel").click(function(){
            $(".tip").fadeOut(100);
        });

    })
}

$(function () {
    message();
})